package org.gtugs.omsk.funnycats.engine.beans;

public class RectArea {
	
	public static RectArea make(Position topLeftCorner, Size size){
		return new RectArea(topLeftCorner, size);
	}
	
	public static RectArea makeFromCenter(Position center, Size size){
		final float x = center.x - size.width / 2.0f;
		final float y = center.y - size.height / 2.0f;
		return new RectArea(Position.make(x, y), size);
	}
	
	public static RectArea make(Position topLeftCorner, Position bottomRightCorner){
		final float width = bottomRightCorner.x - topLeftCorner.x;
		final float height = bottomRightCorner.y - topLeftCorner.y;
		return new RectArea(topLeftCorner, Size.make(width, height));
	}
	
	public static RectArea makeEmpty(){
		return new RectArea(Position.make(0.0f, 0.0f), Size.make(0.0f, 0.0f));
	}
	
	public Position getCenterPosition(){
		final float x = topLeftPoint.x + size.width / 2.0f;
		final float y = topLeftPoint.y + size.height / 2.0f;
		return Position.make(x, y);
	}
	
	public static boolean isIntersection(RectArea f, RectArea s, float eps){
		final Position fp = f.getCenterPosition();
		final Position sp = s.getCenterPosition();
		
		if(Math.abs(fp.x - sp.x) + eps > (f.size.width + s.size.width)/2)return false;
		if(Math.abs(fp.y - sp.y) + eps > (f.size.height + s.size.height)/2)return false;
		return true;
	}
	
	private RectArea(Position topLeftPoint, Size size){
		this.topLeftPoint = topLeftPoint;
		this.size = size;
	}
	
	public final Position topLeftPoint;
	public final Size size;
}
